package com.tq.http;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.AbstractHttpClient;

public class TBaseHttpRequest implements IHttpRequest ,ResponseHandler<IHttpResponse>{

	
	
	
	protected HttpUriRequest  httpUriRequest;
	private AbstractHttpClient httpClient;
	
	
	
	public TBaseHttpRequest(AbstractHttpClient httpClient)
	{
		this.httpClient = httpClient;
		
	}
	
	
	public HttpUriRequest getHttpRequest() {
		
		return httpUriRequest;
	}

	@Override
	public String getRequestURL() {
		
		return httpUriRequest.getURI().toString();
	}

	@Override
	public IHttpResponse request() throws Exception
	{
		
		return httpClient.execute(httpUriRequest, this);
		
	}


	@Override
	public IHttpResponse handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
	
		IHttpResponse rsp = new HttpResponseImpl(response);
		return rsp;
	}

}
